import {
  SITE_COUNTRY_CURRENCY_MAP,
  SITE_COUNTRY_ABBREVIATION_CODE_TO_COMPLETE_CODE_MAP,
} from "@/constants/currency";
import { toUpper } from "lodash-es";

type CountryCode = keyof typeof SITE_COUNTRY_CURRENCY_MAP;
type AbbreviationSiteCountryCode =
  keyof typeof SITE_COUNTRY_ABBREVIATION_CODE_TO_COMPLETE_CODE_MAP;

// 根据站点城市显示对应币种
export const getCurrencyBySiteCountry = (siteCountry: CountryCode) => {
  if (!siteCountry) {
    return "";
  }
  return SITE_COUNTRY_CURRENCY_MAP[toUpper(siteCountry)];
};

// 根据站点城市缩写显示对应币种
export const getCurrencyByAbbreviationSiteCountry = (
  abbreviationSiteCountry: AbbreviationSiteCountryCode
) => {
  const siteCountry =
    SITE_COUNTRY_ABBREVIATION_CODE_TO_COMPLETE_CODE_MAP[
      toUpper(abbreviationSiteCountry)
    ];

  if (!siteCountry) {
    return "";
  }
  return getCurrencyBySiteCountry(siteCountry as CountryCode);
};
